1
|
|
|
/* |
2
|
|
|
* this code is copied from https://openlayers.org/en/latest/examples/custom-interactions.html |
3
|
|
|
* with minimal changes |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
window.app = {}; |
8
|
|
|
var app = window.app; |
9
|
|
|
app.Drag = function() { |
10
|
|
|
ol.interaction.Pointer.call(this, { |
|
|
|
|
11
|
|
|
handleDownEvent: app.Drag.prototype.handleDownEvent, |
12
|
|
|
handleDragEvent: app.Drag.prototype.handleDragEvent, |
13
|
|
|
handleMoveEvent: app.Drag.prototype.handleMoveEvent, |
14
|
|
|
handleUpEvent: app.Drag.prototype.handleUpEvent |
15
|
|
|
}); |
16
|
|
|
|
17
|
|
|
this.coordinate_ = null; |
18
|
|
|
this.cursor_ = 'pointer'; |
19
|
|
|
this.feature_ = null; |
20
|
|
|
this.previousCursor_ = undefined; |
21
|
|
|
}; |
22
|
|
|
|
23
|
|
|
ol.inherits(app.Drag, ol.interaction.Pointer); |
|
|
|
|
24
|
|
|
|
25
|
|
|
app.Drag.prototype.handleDownEvent = function(evt) { |
26
|
|
|
var map = evt.map; |
27
|
|
|
var feature = map.forEachFeatureAtPixel(evt.pixel, |
28
|
|
|
function(feature, layer) { |
|
|
|
|
29
|
|
|
return feature; |
30
|
|
|
}, |
31
|
|
|
{layerFilter: app.Drag.prototype.layerFilter} |
32
|
|
|
); |
33
|
|
|
|
34
|
|
|
if (feature) { |
35
|
|
|
this.coordinate_ = evt.coordinate; |
36
|
|
|
this.feature_ = feature; |
37
|
|
|
} |
38
|
|
|
return !!feature; |
39
|
|
|
}; |
40
|
|
|
|
41
|
|
|
app.Drag.prototype.handleDragEvent = function(evt) { |
42
|
|
|
var map = evt.map; |
43
|
|
|
|
44
|
|
|
var feature = map.forEachFeatureAtPixel(evt.pixel, |
|
|
|
|
45
|
|
|
function(feature, layer) { |
|
|
|
|
46
|
|
|
return feature; |
47
|
|
|
}, |
48
|
|
|
{layerFilter: app.Drag.prototype.layerFilter}); |
49
|
|
|
|
50
|
|
|
var deltaX = evt.coordinate[0] - this.coordinate_[0]; |
51
|
|
|
var deltaY = evt.coordinate[1] - this.coordinate_[1]; |
52
|
|
|
|
53
|
|
|
var geometry = /** @type {ol.geom.SimpleGeometry} */ |
54
|
|
|
(this.feature_.getGeometry()); |
55
|
|
|
geometry.translate(deltaX, deltaY); |
56
|
|
|
|
57
|
|
|
this.coordinate_[0] = evt.coordinate[0]; |
58
|
|
|
this.coordinate_[1] = evt.coordinate[1]; |
59
|
|
|
}; |
60
|
|
|
|
61
|
|
|
app.Drag.prototype.handleMoveEvent = function(evt) { |
62
|
|
|
if (this.cursor_) { |
63
|
|
|
var map = evt.map; |
64
|
|
|
var feature = map.forEachFeatureAtPixel(evt.pixel, |
65
|
|
|
function(feature, layer) { |
|
|
|
|
66
|
|
|
return feature; |
67
|
|
|
}, |
68
|
|
|
{layerFilter: app.Drag.prototype.layerFilter}); |
69
|
|
|
var element = evt.map.getTargetElement(); |
70
|
|
|
if (feature) { |
71
|
|
|
if (element.style.cursor != this.cursor_) { |
72
|
|
|
this.previousCursor_ = element.style.cursor; |
73
|
|
|
element.style.cursor = this.cursor_; |
74
|
|
|
} |
75
|
|
|
} else if (this.previousCursor_ !== undefined) { |
76
|
|
|
element.style.cursor = this.previousCursor_; |
77
|
|
|
this.previousCursor_ = undefined; |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
}; |
81
|
|
|
|
82
|
|
|
app.Drag.prototype.handleUpEvent = function(evt) { |
83
|
|
|
setTmpPointer(evt.coordinate); |
84
|
|
|
this.coordinate_ = null; |
85
|
|
|
this.feature_ = null; |
86
|
|
|
return false; |
87
|
|
|
}; |
88
|
|
|
|
89
|
|
|
app.Drag.prototype.layerFilter = function(layer) { |
90
|
|
|
if (layer === tmpLayer) |
|
|
|
|
91
|
|
|
return(true); |
|
|
|
|
92
|
|
|
else |
93
|
|
|
return(false); |
|
|
|
|
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
|
97
|
|
|
|
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.